package main

import (
	"fmt"
	"os"
)

func main() {
	//scanOut()
	writeFileTest("writeFile")
}

func scanOut()  {
	//标准设备文件(os.Stdout)，默认已经打开，柯直接使用
	//os.Stdout.WriteString("are you ok?\n")
	//os.Stdout.Close() //关闭后，无法输入
	
	var a int
	fmt.Println("please input a:")
	fmt.Scan(&a) //从标准设备中读取内容，放入a中
	fmt.Println("a = ", a)
}

func writeFileTest(path string) {
	file, err := os.Create(path)
	if err != nil {
		fmt.Println("create file error")
		return
	}

	defer file.Close()

	var buf string

	for i:=0; i<10; i++ {

		buf = fmt.Sprintf("i = %d\n", i)

		n, err := file.WriteString(buf)
		if err != nil {
			fmt.Println("wriete file error")
		}
		fmt.Println("n = ", n)

	}

}
